﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MDSAdministration.mdsService;

namespace MDSAdministration
{
    public class MDSManager
    {
        //   // mdsService.ServiceClient context = new mdsService.ServiceClient();
        //    public EntityMembers GetMembers(Identifier modelId, Identifier versionId, Identifier entityId, string SearchTerm)
        //    {
        //        EntityMembersGetCriteria emgc = new EntityMembersGetCriteria();
        //        emgc.EntityId = entityId;
        //        emgc.ModelId = modelId;
        //        emgc.VersionId = versionId;
        //        emgc.AttributeGroupId = new Identifier();
        //        emgc.PageSize = 10000;
        //        emgc.DisplayType = DisplayType.NameCode;
        //        emgc.MemberReturnOption = MemberReturnOption.DataAndCounts;
        //        if (!string.IsNullOrEmpty(SearchTerm.Trim()))
        //            emgc.SearchTerm = SearchTerm;

        //        EntityMembersInformation emi = new EntityMembersInformation();

        //        EntityMembers em;

        //        //using (mdsService.ServiceClient context = new mdsService.ServiceClient())
        //        //{

        //            OperationResult or = new OperationResult();
        //            em = context.EntityMembersGet(new International(), emgc, out emi, out or);

        //        //}

        //        return em;
        //    }

        //    public bool EntitySave()
        //    {
        //        //context.
        //        //EntityMembersUpdate
        //        return true;
        //    }

        //    public Metadata GetMetaData(International intl, ref OperationResult or, Identifier ModelId, Identifier VersionId, Identifier EntityId, MDAction mdAction)
        //    {
        //        MetadataResultOptions mro = new MetadataResultOptions();
        //        MetadataSearchCriteria msc = new MetadataSearchCriteria();

        //        msc.Models = new System.Collections.ObjectModel.Collection<Identifier>() { ModelId }.ToArray();
        //        msc.DerivedHierarchies = new System.Collections.ObjectModel.Collection<Identifier>() { new Identifier() }.ToArray();
        //        msc.AttributeGroups = new System.Collections.ObjectModel.Collection<Identifier>() { new Identifier() }.ToArray();
        //        msc.Versions = new System.Collections.ObjectModel.Collection<Identifier>() { VersionId }.ToArray();
        //        msc.Entities = new System.Collections.ObjectModel.Collection<Identifier>() { EntityId }.ToArray();
        //        msc.Attributes = new System.Collections.ObjectModel.Collection<Identifier>().ToArray();
        //        msc.SearchOption = SearchOption.BothUserDefinedAndSystemObjects;

        //        switch (mdAction)
        //        {
        //            case MDAction.All:
        //                mro.Models = ResultType.Details;
        //                mro.Entities = ResultType.Details;
        //                mro.DerivedHierarchies = ResultType.Details;
        //                mro.Versions = ResultType.Details;
        //                mro.VersionFlags = ResultType.Details;
        //                mro.Attributes = ResultType.Details;
        //                break;
        //            case MDAction.ModelsOnly:
        //                msc.SearchOption = SearchOption.UserDefinedObjectsOnly;
        //                mro.Models = ResultType.Identifiers;
        //                mro.Entities = ResultType.None;
        //                mro.DerivedHierarchies = ResultType.None;
        //                mro.Versions = ResultType.None;
        //                mro.VersionFlags = ResultType.None;
        //                mro.Attributes = ResultType.None;
        //                break;
        //            case MDAction.EntitiesOnly:
        //                mro.Models = ResultType.None;
        //                mro.Entities = ResultType.Identifiers;
        //                mro.DerivedHierarchies = ResultType.None;
        //                mro.Versions = ResultType.None;
        //                mro.VersionFlags = ResultType.None;
        //                mro.Attributes = ResultType.None;
        //                break;
        //            case MDAction.AttributesOnly:
        //                mro.Models = ResultType.None;
        //                mro.Entities = ResultType.None;
        //                mro.DerivedHierarchies = ResultType.None;
        //                mro.Versions = ResultType.None;
        //                mro.VersionFlags = ResultType.None;
        //                mro.Attributes = ResultType.Identifiers;
        //                break;
        //            case MDAction.VersionsOnly:
        //                mro.Models = ResultType.None;
        //                mro.Entities = ResultType.None;
        //                mro.DerivedHierarchies = ResultType.None;
        //                mro.Versions = ResultType.Identifiers;
        //                mro.VersionFlags = ResultType.None;
        //                mro.Attributes = ResultType.None;
        //                break;
        //            case MDAction.FlagsOnly:
        //                mro.Models = ResultType.None;
        //                mro.Entities = ResultType.None;
        //                mro.DerivedHierarchies = ResultType.None;
        //                mro.Versions = ResultType.None;
        //                mro.VersionFlags = ResultType.Identifiers;
        //                mro.Attributes = ResultType.None;
        //                break;
        //            case MDAction.DerivedHierarchiesOnly:
        //                mro.Models = ResultType.None;
        //                mro.Entities = ResultType.None;
        //                mro.DerivedHierarchies = ResultType.None;
        //                mro.Versions = ResultType.None;
        //                mro.VersionFlags = ResultType.None;
        //                mro.Attributes = ResultType.None;
        //                mro.DerivedHierarchies = ResultType.Identifiers;
        //                break;
        //            case MDAction.AttributeGroupsOnly:
        //                mro.Models = ResultType.None;
        //                mro.Entities = ResultType.None;
        //                mro.DerivedHierarchies = ResultType.None;
        //                mro.Versions = ResultType.None;
        //                mro.VersionFlags = ResultType.None;
        //                mro.Attributes = ResultType.None;
        //                mro.AttributeGroups = ResultType.Identifiers;
        //                break;


        //        }

        //        Metadata md = new Metadata();

        //        //using (mdsService.ServiceClient context = new mdsService.ServiceClient())
        //        //{
        //            md = context.MetadataGet(new International(), mro, msc, out or);

        //        //}

        //        return md;
        //    }
        //}
        //public enum MDAction { All, ModelsOnly, EntitiesOnly, AttributesOnly, VersionsOnly, FlagsOnly, DerivedHierarchiesOnly, AttributeGroupsOnly }
    }
}
